package docker_compose

import (
	"context"
	"fmt"
	types2 "github.com/compose-spec/compose-go/v2/types"
	"sigs.k8s.io/yaml"

	"docker-compose/internal/svc"
	"docker-compose/internal/types"
	"github.com/zeromicro/go-zero/core/logx"
)

type GenerateDockerComposeLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGenerateDockerComposeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateDockerComposeLogic {
	return &GenerateDockerComposeLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GenerateDockerComposeLogic) GenerateDockerCompose(req *types.DockerComposeProjectReq) (resp *types.StringResp, err error) {
	// todo: add your logic here and delete this line
	project := types2.Project{Name: req.Name, WorkingDir: "/asdasd"}
	bytes, err := yaml.Marshal(&project)
	fmt.Println(string(bytes))
	return &types.StringResp{
		Result: types.Result{
			Code:      200,
			Message:   "",
			ExtInfo:   "",
			Timestamp: 0,
		},
		Data: string(bytes),
	}, err
}
